package com.charlotte.study.gupao;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @author junjie.ding
 * @data 2021/11/23
 * @description
 */
public class ThreadStatus {

    public static void main(String[] args) {
        // TIMED_WAITING
        new Thread(() -> {
            while (true){
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "TIMED_WAITING").start();

        // WAITING
        new Thread(() -> {
            while (true){
                synchronized (ThreadStatus.class){
                    try {
                        ThreadStatus.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }, "WAITING").start();

        new Thread(new BlockedDemo(), "BlockedDemo - 01").start();
        new Thread(new BlockedDemo(), "BlockedDemo - 02").start();
    }


    static class BlockedDemo extends Thread {
        @Override
        public void run() {
            synchronized (BlockedDemo.class){
                while (true){
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
